package com.example.microinvestcommon.util;
import java.security.SecureRandom;
//此工具类用于生成数字验证码
public class NumericCaptchaGeneratorUtil {

    private static final String DIGITS = "0123456789"; // 数字字符集
    private static final int CAPTCHA_LENGTH = 6; // 验证码长度
    private static final SecureRandom RANDOM = new SecureRandom(); // 安全随机数生成器

    public static String generateNumericCaptcha() {
        StringBuilder captcha = new StringBuilder(CAPTCHA_LENGTH);
        for (int i = 0; i < CAPTCHA_LENGTH; i++) {
            // 从数字字符集中随机选择一个数字
            int index = RANDOM.nextInt(DIGITS.length());
            captcha.append(DIGITS.charAt(index));
        }
        return captcha.toString();
    }
}
